import { defineStore } from "pinia";
import {
	ref
} from "vue";

export const userStore = defineStore("user", () => {
	//存放对象
	//存放用户的基本信息
	const user = ref({});
	//拷贝obj的所有内容赋值给user
	const setUser = (obj) => {
		user.value = {
			...obj
		}
	}
	//清空容器中的值
	const removeUser = () => {
		user.value = {}
	}

	return {
		user,
		setUser,
		removeUser
	}
},
{
	persist: {
		storage: {
			//调整为兼容多端的api，不同的程序中，存放的位置不同
			setItem(key, value) {
				uni.setStorageSync(key, value) // [!code warning]
			},
			getItem(key) {
				return uni.getStorageSync(key) // [!code warning]
			},
		}
	}
})